import React, { Component } from 'react';
import { withRouter } from "react-router-dom";
import { index_goodlist } from '../../utils/api'

class ShopList extends Component {
    state = {
        shoplist: [],
    }
    componentDidMount() {
        index_goodlist({ page:1, count: 27 }).then((res) => {
            this.setState({
                shoplist: res.data.list
            })
        })
    }
    handleChange(id) {
        this.props.history.push({ pathname: '/detail', state: { id } })
    }
    render() {
        return (
            <div className='homelist'>
                <div className='today'></div>
                <div className='goodslist'>
                {
                    this.state.shoplist.map((item, index) => {
                        return (
                            <div className='list' key={index} onClick={()=>{this.handleChange(item.id)}}>
                                <img src={item.pic} alt="" />
                                <div className='name'>{item.name}</div>
                                <span className='price'>{item.salesPrice.name}</span>
                                <div className='buyprice'>抢购价&nbsp;￥&nbsp;<span>{parseInt(item.salesPrice.value)}</span></div>
                            </div>
                        )
                    })
                }
                </div>
                
            </div>
        );
    }
}

export default withRouter(ShopList);